package com.codescholar;

import java.io.*;

public class MdOrder {
    public static void main(String[] args) throws IOException {
        // 源文件
        String path = "数据库1.md";
        // 读取的行
        String line;
        // 面试问题
        String question = "";
        String question2 = "";
        // 答案
        String answer = "";

        // 目标文件
        String path2 = "数据库.md";

        int f = 0;


        File file = new File(path);
        File file2 = new File(path2);
        BufferedReader reader = new BufferedReader(new FileReader(file));
        BufferedWriter writer = new BufferedWriter(new FileWriter(file2));


        while ((line = reader.readLine()) != null){
            f++;
            if (line.length()>1){
                if (line.substring(0,2).equals("##")){

                    System.out.println(answer);
                    writer.write(answer);

                    question2 = question;
                    question = line+"\r\n";

                    if (f == 0){
                        continue;
                    }

                    System.out.println(question2);
                    writer.write(question2);
                    answer = "";
                }else {
                    answer += line+"\r\n";
                }
            }else {
                answer += "\r\n";
            }
        }

        reader.close();
        writer.close();
    }
}
